﻿using Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace RPGGameServer.Tools
{
    public delegate void ExcuteDelegate();
    /// <summary>
    /// 执行管理器，自动给被执行的方法加锁
    /// </summary>
    public class ExcuteManager:Singleton<ExcuteManager>
    {
        //多进程锁
        private Mutex mutex = new Mutex();
        public void ExcuteEx(ExcuteDelegate func)
        {
            lock (this)
            {
                mutex.WaitOne();
                func();
                mutex.ReleaseMutex();
            }
        }

        public static void Excute(ExcuteDelegate func)
        {
            Instance.ExcuteEx(func);
        }
    }
}
